package com.ling.tools.login.utils;

import lombok.Getter;

/**
 * 描述：
 *
 * @author FireLang
 * 创建时间：2020-01-07 10:39
 */

@Getter
public enum ResultInfo {
    SUCCESS(0, 200, "SUCCESS", "操作成功"),
    FAIL(1, 400, "FAIL", "操作失败"),
    FROM_ERROR(1, 401, "FAIL", "表单信息有误"),
    IN_SERVER_ERROR(1, 1000, "服务器错误", "服务器内部异常"),
    USER_NOT_EXIST(1, 1001, null, "用户不存在"),
    USER_INFO_UPDATE_FAIL(1, 1002, null, "用户信息更新失败"),
    USER_PWD_LOGIN_FAIL(1, 1003, null, "用户名或密码错误"),
    EMAIL_LOGIN_FAIL(1, 1004, null, "通过邮箱验证码登录失败"),
    USER_REGISTER_FAIL(1, 1004, null, "用户注册失败"),
    ACCESS_NO_PERMISSION_ERROR(1, 1005, "权限错误", "没有权限，无法操作"),
    UN_KNOW_TOKEN_ERROR(1, 1006, "令牌错误", "TOKEN错误，访问令牌无效"),
    TOKEN_EXPIRE_ERROR(1, 1007, "令牌错误", "TOKEN已过期，请重新登录");

    private Integer state;
    private Integer code;
    private String type;
    private String msg;

    ResultInfo(Integer state, Integer code, String type, String msg) {
        this.state = state;
        this.code = code;
        this.type = type == null? "" : type;
        this.msg = msg;
    }

    public ResultInfo setCode(Integer code) {
        this.code = code;
        return this;
    }

    public ResultInfo setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public ResultInfo setType(String type){
        this.type = type;
        return this;
    }

    public static String getMsg(Integer code) {
        for (ResultInfo resultEnum : ResultInfo.values()) {
            if (resultEnum.code.equals(code)) {
                return resultEnum.msg;
            }
        }
        return null;
    }


}
